import socket


class HostIP(object):
    def __init__(self):
        self.ip = ''
        self.get_host_ip()

    def get_host_ip(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        try:
            s.connect(('8.8.8.8', 80))
            self.ip = s.getsockname()[0]
        except IOError:
            print("socket error!")
        finally:
            s.close()


if __name__ == "__main__":
    hostIp = HostIP()
    print(hostIp.ip)
